from manimlib import *

#75cfb8
#bbdfc8
#f0e5d8
#ffc478

class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        s=6
        r=s/2
        for i in range(22):
            if i%2==0:
                self.add(Square(side_length=s).set_fill('#75cfb8',1))
                s=s/np.sqrt(2)
            else:
                self.add(Circle(radius=r).set_fill(WHITE,1))
                r=r/np.sqrt(2)
        b=Brace(Line([-3,3,0],[-3,-3,0]),LEFT)
        self.add(Text('绿色区域面积=?').next_to(Line([3,3,0],[3,-3,0]),RIGHT),b,Tex('1').next_to(b,LEFT))
        self.wait()
class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        s=6
        r=s/2
        for i in range(22):
            if i%2==0:
                self.add(Square(side_length=s).set_fill('#75cfb8',1))
                s=s/np.sqrt(2)
            else:
                self.add(Circle(radius=r).set_fill(WHITE,1))
                r=r/np.sqrt(2)
        b=Brace(Line([-3,3,0],[-3,-3,0]),LEFT)
        self.add(b,Tex('1').next_to(b,LEFT))
        #
        t1=Tex('b_1').move_to([-2.5,2.5,0])
        t2=Tex('b_2').move_to([-1.7,1.7,0])
        t3=Tex(r'\cdots').move_to([-1.2,1.2,0])
        tk=Tex('b_k').move_to([-0.9,0.9,0])
        self.add(t1,t2,t3,tk)
        self.wait()
class p3(Scene):
    def construct(self):
        # self.add(NumberPlane())
        s=6
        r=s/2
        for i in range(2):
            if i%2==0:
                self.add(Square(side_length=s).set_fill('#75cfb8',1))
                s=s/np.sqrt(2)
            else:
                self.add(Circle(radius=r).set_fill(WHITE,1))
                r=r/np.sqrt(2)
        b=Brace(Line([-3,3,0],[-3,-3,0]),LEFT)
        self.add(b,Tex('1').next_to(b,LEFT))
        #
        t1=Tex('b_1').move_to([-2.5,2.5,0])
        r1=Line(UP*3,ORIGIN)
        tr=Tex('0.5').next_to(r1,LEFT)
        self.add(t1,r1,tr)
        self.wait()
class p4(Scene):
    def construct(self):
        # self.add(NumberPlane())
        s=6
        r=s/2
        for i in range(4):
            if i%2==0:
                self.add(Square(side_length=s).set_fill('#75cfb8',1))
                s=s/np.sqrt(2)
            else:
                self.add(Circle(radius=r).set_fill(WHITE,1))
                r=r/np.sqrt(2)
        b=Brace(Line([-3,3,0],[-3,-3,0]),LEFT)
        self.add(b,Tex('1').next_to(b,LEFT))
        #
        t1=Tex('b_1').move_to([-2.5,2.5,0])
        d1=Line(UP*3,DOWN*3)
        d2=d1.copy().rotate(135*DEGREES)
        t2=Tex('b_2').move_to([-1.7,1.7,0])

        self.add(t1,d1,d2,t2)
        self.wait()